<?php

namespace app\common\model\xilujob;

use think\Db;
use think\Exception;
use think\Log;
use think\Model;

class JobLog extends Model
{
    protected $name = 'xilujob_job_log';
    protected $autoWriteTimestamp = 'int';

    protected $createTime = 'createtime';
    protected $updateTime = false;

    /**
     * 职位添加日志
     * @param int $userId
     * @param Object $job
     */
    public static function record($userId, $job) {
        $log = static::where([
            'company_id'=>$job->publisher_id, 'user_id'=>$userId, 'job_id'=>$job->id
        ])->count();
        if($log) {
            return true;
        }
        try {
            $record = new static();
            $record->save(['user_id'=>$userId,'job_name'=>$job->job_name,'job_id'=>$job->id,'company_id'=>$job->publisher_id]);
        }catch (\Exception $e) {
            Log::error($e->getMessage()."\n".$e->getTraceAsString());
            throw $e;
        }
        return true;
    }

}
